﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;

namespace WastedMechanics
{
    public class AnimComposition
    {
        public List<AnimStatePart> AnimStates;
        public string Name;

        public AnimComposition(string name)
        {
            AnimStates = new List<AnimStatePart>();
            Name = name;
        }

        public void Add(AnimStatePart animState)
        {
            AnimStates.Add(animState);
        }

        public void Enable()
        {
            foreach (var animState in AnimStates)
                animState.Enabled = true;
        }

        public float TimePosition
        {
            get
            {
                float min = 0;
                float minLength = 0;
                foreach (var animState in AnimStates)
                    if (animState.Loop == false)
                    {
                        if (minLength == 0  || animState.Length < minLength)
                        {
                            min = animState.TimePosition;
                            minLength = animState.Length;
                        }
                    }
                return min;
            }
            set
            {
                foreach (var animState in AnimStates)
                    if (animState.Loop == false)
                        animState.TimePosition = value;
            }
        }

        public float Length
        {
            get
            {                
                float minLength = 0;
                foreach (var animState in AnimStates)
                    if (animState.Loop == false)                    
                        if (minLength == 0 || animState.Length < minLength)                                                    
                            minLength = animState.Length;                                            
                return minLength;
            }
        }                  
    }
}
